package cc.iteachyou.template.configuration;

import cc.iteachyou.template.taglib.IDirectiveHandler;
import cc.iteachyou.template.taglib.directives.*;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

@Data
public class TemplateEngineConfiguration {
    public final static String CLASSPATH_PREFIX = "classpath:";
    public final static String FILESYSTEM_PREFIX = "file:";

    public final static String HTMLTAG_PREFIX = "dreamer-cms:";
    // 系统指令
    public final static Map<String, IDirectiveHandler> SYSTEM_DIRECTIVES = new HashMap<>();
    // 自定义指令
    public final static Map<String, IDirectiveHandler> CUSTOM_DIRECTIVES = new HashMap<>();

    private String prefix;
    private String suffix = ".html";
    private Boolean cache = true;
    private String directivePrefix = "dreamer-cms:";

    public void init() {
        // 初始化系统指令
        SYSTEM_DIRECTIVES.put(directivePrefix + "if", new IfDirectiveHandler());
        SYSTEM_DIRECTIVES.put(directivePrefix + "else-if", new IfDirectiveHandler());
        SYSTEM_DIRECTIVES.put(directivePrefix + "else", new ElseDirectiveHandler());
        SYSTEM_DIRECTIVES.put(directivePrefix + "for", new ForDirectiveHandler());
        SYSTEM_DIRECTIVES.put(directivePrefix + "html", new IfDirectiveHandler());
        SYSTEM_DIRECTIVES.put(directivePrefix + "text", new TextDirectiveHandler());
        SYSTEM_DIRECTIVES.put(directivePrefix + "href", new HrefDirectiveHandler());
        SYSTEM_DIRECTIVES.put(directivePrefix + "src", new SrcDirectiveHandler());
        SYSTEM_DIRECTIVES.put(directivePrefix + "title", new TitleDirectiveHandler());
        SYSTEM_DIRECTIVES.put(directivePrefix + "alt", new AltDirectiveHandler());
        SYSTEM_DIRECTIVES.put(directivePrefix + "class", new ClassDirectiveHandler());
        SYSTEM_DIRECTIVES.put(directivePrefix + "id", new IdDirectiveHandler());
        SYSTEM_DIRECTIVES.put(directivePrefix + "name", new NameDirectiveHandler());
        SYSTEM_DIRECTIVES.put(directivePrefix + "value", new ValueDirectiveHandler());
        SYSTEM_DIRECTIVES.put(directivePrefix + "checked", new CheckedDirectiveHandler());
        SYSTEM_DIRECTIVES.put(directivePrefix + "selected", new SelectedDirectiveHandler());

        SYSTEM_DIRECTIVES.put(directivePrefix + "script", new ScriptDirectiveHandler());

        // 初始化系统标签
        SYSTEM_DIRECTIVES.put(directivePrefix + "include", new IncludeDirectiveHandler());
        SYSTEM_DIRECTIVES.put(directivePrefix + "replace", new ReplaceDirectiveHandler());


    }
}
